package sliver.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import sliver.dao.GoodsDao;
import sliver.entity.Goods;

@Repository
public class GoodsDaoImpl extends BaseDaoImpl<Goods> implements GoodsDao{

	@Override
	public List<Goods> findList(Serializable shopperId) {
		
		String queryString = "SELECT DISTINCT g " +
							 "FROM Goods g left join fetch g.categories c left join fetch g.sizes " +
							 "WHERE g.shopper.id = ?" +
							 "ORDER BY g.id ASC";
		
		List<Goods> goods = complexQuery(queryString, new Object[]{shopperId});
		
		return goods;
	}

	@Override
	public List<Goods> findList(Serializable shopperId, Serializable categoryId) {
		
		String queryString = "SELECT g " +
							 "FROM Goods g join g.shopper shop join g.categories c " +
							 "WHERE shop.id = ? " +
							 "AND c.id = ?";
		
		return complexQuery(queryString, new Object[]{shopperId, categoryId});
	}
}
